import requests
import execjs


headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"
}

url = "https://match.yuanrenxue.cn/api/match/1"
# 通过补全的js代码得到签名参数m
with open(r'E:\Python\vscode\Crawlers\yuanrenxue\no1\md5_b.js', 'r', encoding='utf-8') as f:
    js = execjs.compile(f.read())
list_p = []
for i in range(1,6):
    params = {
        'page' : i,
        "m": js.call('request')
    }
    response = requests.get(url, headers=headers, params=params)
    price_data = response.json()['data']
    list_p += [b['value'] for b in price_data]


# 计算平均值
print(list_p)
ave_price = sum(list_p) / len(list_p)
print(ave_price)